package libra.openfeign.fallbackFactory;

import java.util.HashMap;
import java.util.Map;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Component
public class OpenFeignServiceFallbackFactoryImpl 
	implements FallbackFactory<OpenFeignServiceFallbackFactory>{
	
	private static final Map info = Map.of("from", "OpenFeignServiceFallbackFactoryImpl");
	
	@Override
	public OpenFeignServiceFallbackFactory create(Throwable cause) {
		return new OpenFeignServiceFallbackFactory() {
			@Override
			public Object exec() {
				Map copyOf = new HashMap(info);
				copyOf.putAll( Map.of("method", "exec_fallbackFactory()", "fallBackMsg", "") );
				return copyOf;
			}
			@Override
			public Object timeout() {
				Map copyOf = new HashMap(info);
				copyOf.putAll( Map.of("method", "timeout_fallbackFactory()", 
						"fallBackMsg", "执行超时，被fallbackFactory处理",
						"error", cause.getMessage()) );
				return copyOf;
			}
			@Override
			public Object ex() {
				Map copyOf = new HashMap(info);
				copyOf.putAll( Map.of("method", "ex_fallbackFactory()", 
						"fallBackMsg", "执行异常，被fallbackFactory处理", 
						"error", cause.getMessage()) );
				return copyOf;
			}
		};
	}

}
